<script setup lang="ts">
import { IconUser } from "@arco-design/web-vue/es/icon";

interface Props {
  isLogin: boolean; // 是否已经登录
  userImgUrl?: string; // 用户头像图片url
  title?: string; // 导航栏标题
}
defineProps<Props>();

const emit = defineEmits<{
  onTitle: [];
  onSearch: [];
}>();
</script>

<template>
  <div class="navbar-container">
    <div class="title" @click="$emit('onTitle')">
      <img alt="Vue logo" src="@/assets/logo.svg" draggable="false" />
      <span v-if="title">{{ title }}</span>
      <span v-else>hello.vue</span>
    </div>
    <div class="search">
      <div class="search-input-placeholder" @click="$emit('onSearch')">
        <div class="input-left">
          <img alt="search logo" src="@/assets/search.svg" draggable="false" />
          <span>搜索</span>
        </div>
        <div class="input-right">
          <div>⌘</div>
          <div>K</div>
        </div>
      </div>
    </div>
    <div class="navbar-wrapper"></div>
    <div class="tool-log">
      <div class="login">
        <a-avatar v-if="isLogin && userImgUrl">
          <img alt="avatar" :src="userImgUrl" />
        </a-avatar>
        <a-avatar
          v-else-if="isLogin && !userImgUrl"
          :style="{ backgroundColor: '#3370ff' }"
        >
          <IconUser />
        </a-avatar>
        <a-avatar v-else>未登录</a-avatar>
      </div>
      <div class="tool-log-item">
        <div>
          <img alt="notify logo" src="@/assets/notify.svg" draggable="false" />
        </div>
      </div>
      <div class="tool-log-item">
        <div>
          <img
            alt="lang set logo"
            src="@/assets/lang_switch.svg"
            draggable="false"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.navbar-container {
  display: flex;
  width: 100%;
  height: 60px;
  user-select: none;

  .title {
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 30px;
    cursor: pointer;

    img {
      position: relative;
      top: -3px;
      width: 30px;
      height: 30px;
    }

    span {
      margin-left: 10px;
      width: 120px;
      font-size: 20px;
      line-height: 2.5;
      font-weight: bold;
      overflow: hidden; /* 隐藏超出容器的文本 */
      white-space: nowrap; /* 确保文本在一行内显示 */
      text-overflow: ellipsis; /* 超出部分显示为省略号 */
    }
  }

  .search {
    width: 204px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 0 30px;

    .search-input-placeholder {
      height: 32px;
      background-color: rgb(242, 243, 245);
      cursor: pointer;
      border-radius: 50px;
      position: relative;
      &:hover {
        background-color: rgb(229, 230, 235);
      }

      .input-left {
        position: relative;
        top: 9px;
        padding: 0 8px;

        img {
          width: 12px;
          height: 12px;
        }

        span {
          color: $color-grey;
          margin: 0 6px;
          font-size: 14px;
        }
      }

      .input-right {
        position: absolute;
        right: 15px;
        top: 8px;

        div {
          float: right;
          border: 1px solid $color-grey;
          border-radius: 3px;
          width: 17.2px;
          height: 16.2px;
          display: flex;
          align-items: center;
          justify-content: center;
          margin: 0 1px;
          color: $color-grey;
        }
      }
    }
  }

  .navbar-wrapper {
    height: 100%;
    flex-grow: 1;
  }

  .tool-log {
    width: 280px;
    display: flex;
    flex-direction: row-reverse;
    align-items: center;

    .tool-log-item {
      margin-right: 10px;

      div {
        width: 30px;
        height: 30px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;

        &:hover {
          background-color: rgb(242, 243, 245);
        }

        img {
          width: 18px;
          height: 18px;
        }
      }
    }

    .login {
      margin: 0 20px;
      width: 36px;
      height: 36px;
      border-radius: 50%;
      background-color: $color-not-login;
      overflow: hidden;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
    }
  }
}
</style>
